package com.xiaoluo.common.k8s;

import com.squareup.okhttp.Authenticator;
import com.squareup.okhttp.Credentials;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import java.io.IOException;
import java.net.Proxy;

/**
 * Project : XL-CD
 * Package : com.xiaoluo.common.k8s
 * Created by Willian.
 * Date  : 2016/2/1 11:48.
 */
public class K8sAuthenticator implements Authenticator {

    private String userName;
    private String password;

    public K8sAuthenticator(String userName,String password){
        this.userName = userName;
        this.password = password;
    }

    @Override
    public Request authenticate(Proxy proxy, Response response) throws IOException {
        String credential = Credentials.basic(userName, password);
        return response.request().newBuilder().header("Authorization", credential).build();
    }

    @Override
    public Request authenticateProxy(Proxy proxy, Response response) throws IOException {
        return null;
    }
}
